package com.forest.oss.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.forest.oss.IOssClient;
import com.forest.oss.impl.ali.AliOssClient;
import com.forest.oss.impl.ali.AliOssProperties;
import com.forest.oss.impl.huawei.HuaweiOssClient;
import com.forest.oss.impl.huawei.HuaweiOssProperties;
import com.forest.oss.impl.mobilecloud.MobileOssClient;
import com.forest.oss.impl.mobilecloud.MobileOssProperties;
import com.forest.oss.impl.tencent.TencentOssClient;
import com.forest.oss.impl.tencent.TencentOssProperties;

@Configuration
@EnableConfigurationProperties
@Import({AliOssProperties.class, HuaweiOssProperties.class, MobileOssProperties.class, TencentOssProperties.class})
@ConditionalOnClass(IOssClient.class)
public class OssAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "config.oss.huawei",name = "enable",havingValue = "true",matchIfMissing = false)
    public IOssClient huaweiOssClient(HuaweiOssProperties huaweiOssProperties){
        return new HuaweiOssClient(huaweiOssProperties);
    }

    @Bean
    @ConditionalOnProperty(prefix = "config.oss.ali",name = "enable",havingValue = "true",matchIfMissing = false)
    public IOssClient aliOssClient(AliOssProperties aliOssProperties){
        return new AliOssClient(aliOssProperties);
    }

    @Bean
    @ConditionalOnProperty(prefix = "config.oss.mobile",name = "enable",havingValue = "true",matchIfMissing = false)
    public IOssClient mobileOssClient(MobileOssProperties mobileOssProperties){
        return new MobileOssClient(mobileOssProperties);
    }

    @Bean
    @ConditionalOnProperty(prefix = "config.oss.tencent",name = "enable",havingValue = "true",matchIfMissing = false)
    public IOssClient tencentOssClient(TencentOssProperties tencentOssProperties){
        return new TencentOssClient(tencentOssProperties);
    }
}
